package com.wangyonghao.harmonyocrs.utils;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
//import ohos.global.icu.util.TimeZone;

public class DateUtils {
    public static final String dateFormat = "yyyy-MM-dd";
    public static final String datetimeFormat = "yyyy-MM-dd HH:mm:ss";
    private static SimpleDateFormat dateSDF = new SimpleDateFormat(dateFormat, Locale.getDefault());
    private static SimpleDateFormat datetimeSDF = new SimpleDateFormat(datetimeFormat, Locale.getDefault());

    static {
        dateSDF.setTimeZone(TimeZone.getTimeZone("GMT+0"));
        datetimeSDF.setTimeZone(TimeZone.getTimeZone("GMT+0"));
    }

    public static final Date now() {
        return new Date(System.currentTimeMillis());
    }

    public static final String dateToString(Date date) {
        return dateSDF.format(date);
    }

    public static final String datetimeToString(Date date) {
        return datetimeSDF.format(date);
    }

    public static final String datetimeToString(long date) {
        return datetimeSDF.format(date);
    }

    public static final Date stringToDate(String s) {
        Date date = null;
        try {
            date = dateSDF.parse(s);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
